from django.contrib.auth.models import User
from django.db import models

# Create your models here.
# 文章分类表
class Classes(models.Model):
    name = models.CharField(max_length=20, unique=True)

    # class Meta:
    #     db_table = "ly_order"
    #     verbose_name = "订单记录"
    #     verbose_name_plural = "订单记录"
    def __str__(self):
        return self.name
# 用户详情表
class UserDetail(models.Model):
    age = models.IntegerField(null=True, blank=True)
    sex = models.BooleanField(null=True, blank=True)
    user = models.OneToOneField(User, on_delete=models.CASCADE)
    pass
# 标签表
class Label(models.Model):
    name = models.CharField(max_length=30, unique=True)
    def __str__(self):
        return self.name
# 文章表
class Article(models.Model):
    title = models.CharField(max_length=50)
    desc = models.CharField(max_length=150)
    content = models.TextField(null=True)
    cover = models.TextField(null=True)
    create_time = models.DateTimeField(auto_now_add=True)
    update_time = models.DateTimeField(auto_now=True)
    classes = models.ForeignKey(Classes, on_delete=models.NOT_PROVIDED)
    user = models.ForeignKey(User, on_delete=models.CASCADE)
    labels = models.ManyToManyField(Label)
    def __str__(self):
        return self.title